import { create } from "zustand";
import {  Toast } from 'antd-mobile'
import { getChannelList } from "../api/layout";
import { Action } from "antd-mobile/es/components/action-sheet";
import { GET_TOKEN } from "@/utils/token";

const userStore = create(
    (set) => ({
        token:'',
        index:0,
        channelList:[],
        setIndex:function(data:number){
            set({index:data})
        }
       ,
       list:[],
       setList:(data:[])=>(set({list:data})),
        setToken:(data:string)=>(set({token:data})),
        toGetChannelList:async()=>{
            let result = await getChannelList();
            if(result&&result.status===200){
               
                 set({channelList:result.data.data.channels})
            
            }else{
                Toast.show({
                    icon: 'fail',
                    content: '获取文章列表失败！',
                  })
            }
        }
    })
)

export default userStore